package com.lengmou.service.impl;

import com.lengmou.dao.GoodsCommentDao;
import com.lengmou.entity.GoodsComment;
import com.lengmou.service.GoodsCommentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service("GoodsCommentService")
public class GoodsCommentServiceImpl implements GoodsCommentService {
    @Resource
    private GoodsCommentDao gcd;
    @Override
    public List<GoodsComment> getAll() {

        return gcd.querysAll();
    }

    @Override
    public List<GoodsComment> getCommentByGoodsId(int goodsid) {
        return gcd.querysByGoodsId(goodsid);
    }

    @Override
    public List<GoodsComment> getByUsersid(int userid) {
        return gcd.querysByUsersid(userid);
    }
    @Override
    public List<GoodsComment> getByLevel(int level) {
        return gcd.querysByLevel(level);
    }

    @Override
    public GoodsComment getById(int id) {
        return gcd.querysById(id);
    }

    @Override
    public int addGoodsComment(GoodsComment comment) {
        return gcd.addGoodsComment(comment);
    }

    @Override
    public int setCommnentContent(GoodsComment comment) {
        GoodsComment byId = getById(comment.getId());
        if(byId!=null){
            byId.setContent(comment.getContent());
            return gcd.updateGoodsCommnent(byId);
        }
        return -1;
    }

    @Override
    public int setCommnentLevel(GoodsComment comment) {
        GoodsComment byId = getById(comment.getId());
        if(byId!=null){
            byId.setLevel(comment.getLevel());
            return gcd.updateGoodsCommnent(byId);
        }
        return -1;
    }

    @Override
    public int setCommentUserId(GoodsComment comment) {
        GoodsComment byId = getById(comment.getId());
        if(byId!=null){
            byId.setUserid(comment.getUserid());
            return gcd.updateGoodsCommnent(byId);
        }
        return -1;
    }

    @Override
    public int setCommentTime(GoodsComment comment) {

        GoodsComment byId = getById(comment.getId());
        if(byId!=null){
            byId.setCreatetime(comment.getCreatetime());
            return gcd.updateGoodsCommnent(byId);
        }
        return -1;
    }

    @Override
    public int deleteGoodsComment(int id) {
        GoodsComment byId = getById(id);
        if(byId!=null){
            return gcd.deleteGoodsComment(id);
        }
        return -1;
    }
}
